package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

import static org.jsola.core.example.BaseExample.E_MODIFIED_USER_ID;
import static org.jsola.core.example.BaseExample.N_MODIFIED_USER_ID;

/**
 *
 * @author wxz
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class AttendRecordStatQuery extends BaseQuery {

    /** 公司ID */
    @ApiParam(value = "公司ID", example = "")
    @NotNull(message = "公司ID不能为空")
    private String companyId;

    /** 员工姓名 */
    @ApiParam(value = "员工姓名", example = "")
    private String empInfoName;

    /** 部门ID */
    @ApiParam(value = "部门ID", example = "")
    private String deptId;

    /** 日期: yyyy-MM-dd */
    @ApiParam(value = "日期: yyyy-MM-dd", example = "")
    private String ymd;

    /** 打卡状态 */
    @ApiParam(value = "打卡状态;0-全部,1-正常,2-异常", example = "")
    private Integer punchStatus;

    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;

    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public AttendRecordStatQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }
}
